﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LockWarehouse.ascx.cs" Inherits="ERP.Modules.LockWarehouse" %>
<script>
    var edit = function (editor, e) {
        if (e.record.data.LockWarehouse_Detail_Test > e.record.data.LockWarehouse_Detail_TD) {
            //Ext.Msg.alert("Lỗi", "Số lượng nhập phải nhỏ hơn số lượng còn lại!");
            window.Ext.MessageBox.show({
                title: 'Lỗi',
                msg: "Số lượng kiểm tra phải nhỏ hơn số lượng tồn đầu !",
                buttons: window.Ext.MessageBox.OK,
                icon: window.Ext.MessageBox.ERROR
            });
            e.record.reject();
        }
    };
</script>
<%-------------------------------%>
<ext:Hidden ID="FormatTypeLockWarehouse" runat="server" />
<ext:Panel runat="server" Layout="Fit" Border="False" ID="PanelLockWarehouse">
    <Content>
        <%--------------GridLockWarehouse-----------------%>
        <ext:GridPanel
            ID="grLockWarehouse"
            Cls="grid-double"
            runat="server"
            EnableColumnMove="true"
            Border="False">
            <Store>
                <%-------------StoreLockWarehouse-----------------%>
                <ext:Store
                    ID="StoreLockWarehouse"
                    runat="server"
                    OnReadData="StoreLockWarehouse_RefreshData"
                    PageSize="20">
                    <Model>
                        <ext:Model ID="ModelLockWarehouse" runat="server" IDProperty="LockWarehouse_ID">
                            <Fields>
                                <ext:ModelField Name="LockWarehouse_User" Type="String" />
                                <ext:ModelField Name="LockWarehouse_No" Type="String" />
                                <ext:ModelField Name="LockWarehouse_Date" Type="Date" />
                                <ext:ModelField Name="LockWarehouse_Note" Type="String" />
                                <ext:ModelField Name="LockWarehouse_Test" Type="String" />
                                <ext:ModelField Name="LockWarehouse_Detail_TD" Type="Int" />
                                <ext:ModelField Name="LockWarehouse_Detail_NTK" Type="Int" />
                                <ext:ModelField Name="LockWarehouse_Detail_XTK" Type="Int" />
                                <ext:ModelField Name="LockWarehouse_Detail_TC" Type="Int" />
                                <ext:ModelField Name="LockWarehouse_Detail_Test" Type="Int" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:RowNumbererColumn ID="RowNumbererColumn1" Text="STT" runat="server" Width="30" Align="Center" />
                    <ext:Column ID="Column2" runat="server" Text="Người chốt" Width="150" DataIndex="LockWarehouse_User"></ext:Column>
                    <ext:DateColumn ID="Column3" runat="server" Text="Ngày chốt" DataIndex="LockWarehouse_Date" Format="dd-MM-yyyy"></ext:DateColumn>
                    <ext:Column ID="Column1" runat="server" Text="Tồn đầu" DataIndex="LockWarehouse_Detail_TD"></ext:Column>
                    <ext:Column ID="Column5" runat="server" Text="Nhập TK" DataIndex="LockWarehouse_Detail_NTK"></ext:Column>
                    <ext:Column ID="Column6" runat="server" Text="Xuất TK" DataIndex="LockWarehouse_Detail_XTK"></ext:Column>
                    <ext:Column ID="Column7" runat="server" Text="Tồn cuối" DataIndex="LockWarehouse_Detail_TC"></ext:Column>
                    <ext:Column ID="Column9" runat="server" Text="SL kiểm tra" DataIndex="LockWarehouse_Detail_Test"></ext:Column>
                    <ext:Column ID="Column8" runat="server" Text="Người kiểm tra" DataIndex="LockWarehouse_Test"></ext:Column>
                    <ext:Column ID="Column4" runat="server" Text="Ghi chú" Width="100" DataIndex="LockWarehouse_Note" Flex="1"></ext:Column>
                </Columns>
            </ColumnModel>
            <DirectEvents>
                <ItemDblClick OnEvent="LockWarehouseDblClick">
                    <ExtraParams>
                        <ext:Parameter Name="LockWarehouse_ID" Value="record.data.LockWarehouse_ID" Mode="Raw" />
                    </ExtraParams>
                    <EventMask ShowMask="true" Msg="Đang tải..." />
                </ItemDblClick>
            </DirectEvents>
            <SelectionModel>
                <ext:CheckboxSelectionModel ID="CheckboxSelectionModelLockWarehouse" runat="server" Mode="Multi">
                    <Listeners>
                        <SelectionChange Handler="
                            if (selected.length == 0) {
                                #{btnEdit}.disable();
                                #{btnDel}.disable();
                                #{btnExport}.disable();
                            } else {
                                #{btnEdit}.enable();
                                #{btnDel}.enable();
                                #{btnExport}.enable();
                            }" />
                    </Listeners>
                </ext:CheckboxSelectionModel>
            </SelectionModel>
            <DockedItems>
                <ext:Toolbar ID="ToolbarTopMain" runat="server" Dock="Top">
                    <Items>
                        <ext:Button ID="btnAddNew" runat="server" Text="Chốt kho" Icon="ApplicationAdd">
                            <DirectEvents>
                                <Click OnEvent="Lock_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:Button ID="btnDel" runat="server" Text="Hủy chốt kho" Icon="ApplicationDelete">
                            <DirectEvents>
                                <Click OnEvent="UnLock_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                    <ExtraParams>
                                        <ext:Parameter Name="name" Value="btnDel"></ext:Parameter>
                                    </ExtraParams>
                                    <Confirmation ConfirmRequest="true"
                                        Title="Thông Báo" Message="Bạn có muốn hủy lần chốt kho này không ?">
                                    </Confirmation>
                                </Click>
                            </DirectEvents>
                        </ext:Button>

                        <ext:Button ID="btnExport" runat="server" Text="Xuất tập tin" Icon="Printer">
                            <Menu>
                                <ext:Menu ID="MenuMain" runat="server">
                                    <Items>
                                        <ext:MenuItem ID="MenuItemExportXML" runat="server" Text="XML" Icon="PageCode">
                                            <Listeners>
                                                <Click Handler="submitValue(#{grLockWarehouse}, #{FormatTypeLockWarehouse}, 'xml');" />
                                            </Listeners>
                                        </ext:MenuItem>
                                    </Items>
                                </ext:Menu>
                            </Menu>
                        </ext:Button>

                    </Items>
                </ext:Toolbar>
                <ext:Toolbar ID="ToolbarPagging" runat="server" Dock="Bottom" AnchorHorizontal="100%">
                    <Items>
                        <ext:TriggerField ID="txtSearch" runat="server" Width="200" EnableKeyEvents="true" MarginSpec="0 8 0 0">
                            <Triggers>
                                <ext:FieldTrigger Icon="Search" />
                            </Triggers>
                            <DirectEvents>
                            </DirectEvents>
                        </ext:TriggerField>
                        <ext:PagingToolbar ID="PagingToolbarLockWarehouse" runat="server" StoreID="StoreLockWarehouse" BeforePageText="Trang" AfterPageText="của {0}" LastText="Cuối" NextText="Kế tiếp" PrevText="Trở lại" FirstText="Đầu" RefreshText="Làm tươi" DisplayInfo="true" DisplayMsg="Trang {0} - {1} của {2}" />
                    </Items>
                </ext:Toolbar>
            </DockedItems>
        </ext:GridPanel>
    </Content>
</ext:Panel>
<ext:Panel ID="Panel1" runat="server">
    <Content>
        <%-----------WindowsLockWarehouse-----------------%>
        <ext:Window ID="WindowsLockWarehouse" runat="server"
            Title="Cập nhật chốt kho"
            DefaultAnchor="100%"
            Width="832px"
            Height="531px"
            Hidden="true"
            AutoScroll="false"
            Maximizable="False"
            Minimizable="False"
            AutoDataBind="true"
            Region="Center"
            Resizable="false"
            Modal="true"
            HideMode="Offsets"
            Border="false"
            Padding="5"
            DefaultButton="btnSavePopUp">
            <Items>
                <ext:Toolbar ID="ToolbarLockWarehouse" runat="server">
                    <Items>
                        <ext:Button runat="server" Text="Lưu lại" Icon="Disk" ID="btnSavePopUp">
                            <DirectEvents>
                                <Click OnEvent="SavePopup_Click" Before="return #{FormPanelLockWarehouse}.isValid();">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                    <ExtraParams>
                                        <ext:Parameter Name="grLockWarehouse_Detail" Value="Ext.encode(#{grLockWarehouse_Detail}.getRowsValues({selectedOnly : false}))" Mode="Raw" />
                                    </ExtraParams>
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:Button runat="server" Text="Huỷ bỏ" Icon="Decline" ID="btnCancelPopUp">
                            <Listeners>
                                <Click Handler="#{WindowsLockWarehouse}.hide();"></Click>
                            </Listeners>
                        </ext:Button>
                        <ext:TextField ID="txtLockWarehouse_ID" runat="server" FieldLabel="ID" LabelAlign="Right" Hidden="true" />
                    </Items>
                </ext:Toolbar>
                <ext:FormPanel ID="FormPanelLockWarehouse" runat="server"
                    AutoHeight="true"
                    BodyPadding="10"
                    Frame="true"
                    DefaultAnchor="100%">
                    <Items>
                        <ext:TextField ID="txtLockWarehouse_No" runat="server" FieldLabel="Mã chốt kho" AnchorHorizontal="100%" AllowBlank="false" />
                        <ext:TextField ID="txtLockWarehouse_Test" runat="server" FieldLabel="Người kiểm tra" AnchorHorizontal="100%" AllowBlank="false" />
                        <ext:TextArea ID="txtLockWarehouse_Note" runat="server" FieldLabel="Ghi chú" AnchorHorizontal="100%" />
                        <ext:GridPanel
                            ID="grLockWarehouse_Detail"
                            Cls="grid-double"
                            runat="server"
                            EnableColumnMove="true"
                            AutoWidth="true"
                            AutoScroll="true"
                            Layout="Fit"
                            Height="300">
                            <Store>
                                <ext:Store
                                    ID="StoreLockWarehouse_Detail"
                                    runat="server"
                                    OnReadData="StoreLockWarehouse_Detail_RefreshData">
                                    <Model>
                                        <ext:Model ID="ModelLockWarehouse_Detail" runat="server" IDProperty="Warehouse_Id">
                                            <Fields>
                                                <ext:ModelField Name="Warehouse_Alias" Type="String" />
                                                <ext:ModelField Name="Warehouse_Name" Type="String" />
                                                <ext:ModelField Name="LockWarehouse_Detail_TD" Type="Int" />
                                                <ext:ModelField Name="LockWarehouse_Detail_NTK" Type="Int" />
                                                <ext:ModelField Name="LockWarehouse_Detail_XTK" Type="Int" />
                                                <ext:ModelField Name="LockWarehouse_Detail_TC" Type="Int" />
                                                <ext:ModelField Name="LockWarehouse_Detail_Test" Type="Int" />
                                                <ext:ModelField Name="LockWarehouse_Detail_TestName" Type="String" />
                                            </Fields>
                                        </ext:Model>
                                    </Model>
                                </ext:Store>
                            </Store>
                            <ColumnModel runat="server">
                                <Columns>
                                    <ext:RowNumbererColumn ID="RowNumbererColumn2" Text="STT" runat="server" Width="30" Align="Center" />
                                    <ext:Column ID="Column10" runat="server" Text="Mã kho" Width="100" DataIndex="Warehouse_Alias" />
                                    <ext:Column ID="Column11" runat="server" Text="Tên kho" Width="100" DataIndex="Warehouse_Name" />
                                    <ext:Column ID="Column12" runat="server" Text="Tồn đầu" Width="90" DataIndex="LockWarehouse_Detail_TD" />
                                    <ext:Column ID="Column25" runat="server" Text="Nhập TK" Width="90" DataIndex="LockWarehouse_Detail_NTK" />
                                    <ext:Column ID="Column26" runat="server" Text="Xuất TK" Width="90" DataIndex="LockWarehouse_Detail_XTK" />
                                    <ext:Column ID="Column27" runat="server" Text="Tồn cuối" Width="90" DataIndex="LockWarehouse_Detail_TC" />
                                    <ext:Column ID="Column13" runat="server" Text="SL kiểm tra" Width="90" DataIndex="LockWarehouse_Detail_Test">
                                        <Editor>
                                            <ext:NumberField runat="server" MinValue="0">
                                            </ext:NumberField>
                                        </Editor>
                                    </ext:Column>
                                    <ext:Column ID="Column14" runat="server" Text="Người kiểm tra" Width="90" DataIndex="LockWarehouse_Detail_TestName" Flex="1">
                                        <Editor>
                                            <ext:TextField runat="server" MinValue="0">
                                            </ext:TextField>
                                        </Editor>
                                    </ext:Column>
                                </Columns>
                            </ColumnModel>
                            <Plugins>
                                <ext:RowEditing ID="RowEditing1" runat="server" SaveBtnText="Cập nhật" CancelBtnText="Hủy bỏ">
                                    <DirectEvents>
                                        <Edit>
                                            <ExtraParams>
                                                <ext:Parameter Name="Quotes_Materials" Value="Ext.encode(#{grLockWarehouseMaterials}.getRowsValues({selectedOnly : true}))" Mode="Raw" />
                                            </ExtraParams>
                                        </Edit>
                                    </DirectEvents>
                                    <Listeners>
                                        <Edit Fn="edit"></Edit>
                                    </Listeners>
                                </ext:RowEditing>
                            </Plugins>
                        </ext:GridPanel>
                    </Items>
                </ext:FormPanel>
            </Items>
        </ext:Window>
    </Content>
</ext:Panel>
